const mongoose = require("mongoose")

var Schema = mongoose.Schema

// 管理员
var AdminUserSchema = new Schema({
    username: {
        type: String,
        required: true
    },
    password: {
        type:String,
        required: true,
    },
    name: {
        type: String,
        required: true
    },
    status: {
        type: String,
        default: "3"
    },
    role: {
        type: String,
        default: "any"
    }
}, {
    timestamps: {
        createdAt: "addtime",
        updatedAt: "updatetime"
    }
})

// 会员
var UserSchema = new Schema({
    nickname: {
        type: String,
        required: true
    },
    avatar: {
        type:String,
        
    },
    money: {
        type: Number,
        default: 0
    },
    phone: {
        type: String
    },
    name: {
        type: String, 
    },
    email: {
        type: String, 
    },
    openid: {
        type: String
    },
    status: {
        type: String,
        default: "1"
    },
    qrcode: {
        type: String
    },
    // 角色  1 普通会员  2 医生
    role: {
        type: String,
        default: "1"
    },
    beLong: {
        type: Schema.Types.ObjectId,
        ref: "users"
    },
    sub: {
        type: Schema.Types.ObjectId,
        ref: "users"
    },
    // 是否是分销员 2 不是  1 是
    distribution: {
        type: String,
        default: "2"
    },
    children: [
        {
            type: Schema.Types.ObjectId,
            ref: "users"
        }
    ],
    mydangan: [{
        type: Schema.Types.ObjectId,
        ref: "dangan"
    }],
    mypatient: [

            {
                type: Schema.Types.ObjectId,
                ref: "users"
            } 
    
    ],
    mydoctors: [
        {
            type: Schema.Types.ObjectId,
            ref: "users"
        }
    ],
    addressList: [
        {
            type: Schema.Types.ObjectId,
            ref: "address"
        }
    ]
}, {
    timestamps: {
        createdAt: "addtime",
        updatedAt: "updatetime"
    }
})

// 会员档案
var DangAnSchema = new Schema({
    // 属于谁
    beLong: {
        type: Schema.Types.ObjectId,
        ref: "users"
    },
    // 关系
    relationship: {
        type: String,
        required: true
    },
    // 性别 1 男  2女
    gender: {
        type:String,
        required: true,
    },
    name: {
        type: String,
        required: true
    },
    birthday: {
        type: String,
    },
    // 身高
    top: {
        type: String,
    },
    // 体重
    weight: {
        type: String,
    },
    // 体重
    yaowei: {
        type: String,
    },
    // issmoke 是否有吸烟史
    issmoke: {
        type: String,
    },
    // isdriking 是否有饮酒史
    isdriking: {
        type: String,

    },
    // 肝功 1 正常   2 异常
    liver: {
        type: String,
        default: "1"
    },
    // 肾 1 正常   2 异常
    kidney: {
        type: String,
        default: "1"
    },
    // 婚姻 1 已婚   2 未婚  3 保密
    marry: {
        type: String,
        default: "3"
    },
    // 慢性病
    man: {
        type: Array,
       
    },
    // 家族病史
    family: {
        type: Array,
        
    },
    // 药物过敏
    guomin: {
        type: Array,
        
    },
    //  生育状态
    hasChildren: {
        type: String
    },
    // 食物/接触过敏
    foodguomin: {
        type: Array,
        
    },
    // 个人习惯
    selfdone: {
        type: Array,
        
    },
    status: {
        type: String,
        default: "1"
    },
}, {
    timestamps: {
        createdAt: "addtime",
        updatedAt: "updatetime"
    }
})

var AddressList = new Schema({
    name: {
        type: String,
        required: true
    },
    phone: {
        type: String,
        required: true
    },
    left: {
        type: String
    },
    top: {
        type: String
    },
    address: {
        type: String,
        required: true
    },
    province: {
        type: String
    },
    city: {
        type: String
    },
    country: {
        type: String
    },
    status: {
        type: String,
        default: "1"
    },
    provinceCode: {
        type: String
    },
    cityCode: {
        type: String
    },
    countryCode: {
        type: String
    },
    defaultAdd: {
        type: String,
        default: "2"
    }
})

module.exports = {
    AdminUser: mongoose.model("adminuser", AdminUserSchema),
    User: mongoose.model("users",UserSchema),
    DangAn: mongoose.model("dangan",DangAnSchema),
    AddressList: mongoose.model("address", AddressList)
}